#include "updatadialog.h"
#include "ui_updatadialog.h"

updatadialog::updatadialog(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::updatadialog)
{
    ui->setupUi(this);
}

updatadialog::~updatadialog()
{
    delete ui;
}

void updatadialog::setUpdateRecord(QSqlRecord &recData)
{
    m_record=recData;    //记录存入私有变量
    ui->IDEdit->setEnabled(false);
    ui->IDEdit->setText(recData.value("ID").toString());    //员工编号不允许编辑
    setWindowTitle("更新记录");

    //根据recData的数据更新界面显示
    if((recData.value("shopname").toString())=="")
    {ui->shopnameEdit->setEnabled(false);}
    else{ui->shopnameEdit->setText(recData.value("shopname").toString());}
   // ui->shopnameEdit->setText(recData.value("shopname").toString());
    if((recData.value("sale").toString())=="")
    {ui->saleEdit->setEnabled(false);}
    else{ui->saleEdit->setText(recData.value("sale").toString());}
   // ui->saleEdit->setText(recData.value("sale").toString());
    if(!((recData.value("name").toString())=="")){
        ui->nameEdit->setText(recData.value("name").toString());}
    else{ui->nameEdit->setEnabled(false); }
    //ui->phoneEdit->setText(recData.value("phone").toString());
    if(!((recData.value("phone").toString())=="")){
        ui->phoneEdit->setText(recData.value("phone").toString());}
    else{ui->phoneEdit->setEnabled(false); }
    //ui->orderEdit->setText(recData.value("orderid").toString());
    if(!((recData.value("orderid").toString())=="")){
        ui->orderEdit->setText(recData.value("orderid").toString());}
    else{ui->orderEdit->setEnabled(false); }
    //ui->passEdit->setText(recData.value("Password").toString());
    if(!((recData.value("Password").toString())=="")){
        ui->passEdit->setText(recData.value("Password").toString());}
    else{ui->passEdit->setEnabled(false); }
    //ui->addreEdit->setText(recData.value("addre").toString());
    if(!((recData.value("addre").toString())=="")){
        ui->addreEdit->setText(recData.value("addre").toString());}
    else{ui->addreEdit->setEnabled(false); }
    //ui->wayEdit_2->setText(recData.value("way").toString());
    if(!((recData.value("money").toString())=="")){
        ui->wayEdit_2->setText(recData.value("money").toString());}
    else{ui->wayEdit_2->setEnabled(false); }
    //ui->wayEdit->setText(recData.value("monoy").toString());
    if(!((recData.value("way").toString())=="")){
        ui->wayEdit->setText(recData.value("way").toString());}
    else{ui->wayEdit->setEnabled(false); }
    if(!((recData.value("time").toString())=="")){
        ui->addreEdit_2->setText(recData.value("time").toString());}
    else{ui->addreEdit_2->setEnabled(false); }
    if(!((recData.value("cuisine").toString())=="")){
        ui->addreEdit_3->setText(recData.value("cuisine").toString());}
    else{ui->addreEdit_3->setEnabled(false); }
    if(!((recData.value("mark").toString())=="")){
        ui->addreEdit_4->setText(recData.value("mark").toString());}
    else{ui->addreEdit_4->setEnabled(false); }
    if((recData.value("shopname").toString())!=""&&
        (recData.value("sale").toString())!=""){
        ui->label_14->setText("天");
    }else{
        ui->label_14->setText("分钟");
    }


}
//点击"确定"按钮后，界面数据保存到记录变量mRecord
QSqlRecord updatadialog::getRecordData()
{
    m_record.setValue("shopname",   ui->shopnameEdit->text());
    m_record.setValue("sale",    ui->saleEdit->text());
   m_record.setValue("name",  ui->nameEdit->text());
   m_record.setValue("orderid",ui->orderEdit->text());
    m_record.setValue("addre",    ui->addreEdit->text());
   m_record.setValue("monoy",  ui->wayEdit_2->text());
    m_record.setValue("time",  ui->addreEdit_2->text());
   m_record.setValue("phone",  ui->phoneEdit->text());
    m_record.setValue("way",    ui->wayEdit->text());
   m_record.setValue("Password",    ui->passEdit->text());
    m_record.setValue("ID",    ui->IDEdit->text());
   m_record.setValue("cuisine",    ui->addreEdit_3->text());
    m_record.setValue("mark",    ui->addreEdit_4->text());
    qDebug()<<"m_record:      "<<ui->addreEdit_2->text();
    return  m_record; //以记录作为返回值
}

void updatadialog::on_pushButton_clicked()
{
    accept(); // 触发 accepted 信号
}

